﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using Spritehand.FarseerHelper;

namespace nRoute.Samples.SquareAway.Behaviors
{
    /// <remarks>
    /// Idea from http://rd3d2.spaces.live.com/blog/cns!E8560F926A112380!21264.entry
    /// </remarks>
    public class PlayAudioAction 
        : TriggerAction<UIElement>
    {
        private SoundMain _sound;

#region Properties

        public string AudioResourceUrl { get; set; }

#endregion

#region Overrides

        protected override void OnAttached()
        {
            base.OnAttached();

            if (!string.IsNullOrEmpty(AudioResourceUrl))
            {
                _sound = new SoundMain(null, AudioResourceUrl, 2, 0);
            }
        }

        protected override void Invoke(object parameter)
        {
            if (_sound != null) _sound.Play();
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();

            _sound = null;
        }

#endregion

    }
}
